﻿@{
    ViewBag.Title = "NAVSet";
}
@section scripts
{
    <link rel="stylesheet" href="../Scripts/kindeditor-4.1.10/themes/default/default.css" />
    <script charset="utf-8" src="../Scripts/kindeditor-4.1.10/kindeditor-min.js"></script>
    <script charset="utf-8" src="../Scripts/kindeditor-4.1.10/lang/zh_CN.js"></script>
    <script src="@Url.Content("~/Scripts/shared/share.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Scripts/shared/shown.js")" type="text/javascript"></script>
    <link href="~/Scripts/miniui/themes/default/medium-mode.css" rel="stylesheet" type="text/css" />
}
<form id="form1" runat="server" method="post" style="height: 100%">
    <div class="mini-toolbar" style="padding: 2px; border-top: 0; border-left: 0; border-right: 0;">
        <table width="1000px;">
            <tr>
                <td width="1000px;">
                    <a class="mini-button" id="save" name="save" iconcls="icon-save" onclick="SaveInfo" plain="true">保存</a>
                    <span class="separator"></span>
                    <a class="mini-button" id="close" iconcls="icon-close" onclick="CloseWindow" plain="true">关闭</a>
                </td>
            </tr>
        </table>
    </div>

    <table style="margin-top:15px;margin-left:15px">
        <tr>
            <td width="70px" height="40px" align="right">编码：</td>
            <td width="190px" height="40px" align="left">
                <input name="FNumber" class="mini-textbox" style="width: 190px;" required="true" TabIndex="1" />
            </td>
            <td width="70px" height="40px" align="right">类型：</td>
            <td width="190px" height="40px" align="left">
                <input name="comdatatype" class="mini-combobox" style="width: 190px;" value="0"
                       shownullitem="false" required="true" allowinput="false" align="left" data="mdatatype" TabIndex="4" />
            </td>
            <td width="70px" align="right">图片URL：</td>
            <td width="190px" align="left">
                <input name="FImgUrl" class="mini-textbox" style="width: 190px;" />
            </td>
        </tr>
        <tr>
            <td width="70px" height="40px" align="right">导航名称：</td>
            <td width="190px" height="40px" align="left">
                <input name="FName" class="mini-textbox" style="width: 190px;" required="true" TabIndex="2" />
            </td>
            <td width="70px" height="40px" align="right">排序：</td>
            <td width="190px" height="40px" align="left">
                <input name="FOrder" class="mini-spinner" style="width:190px;" minValue="0" maxValue="100" showbutton="false" TabIndex="5" />
            </td>
            <td></td>
            <td rowspan="3"><img id="Image0" src="~/Content/Images/NoImage.jpg" Width="190" height="120" /></td>
        </tr>
        <tr>
            <td width="70px" height="40px" align="right">备注：</td>
            <td width="190px" height="40px" align="left">
                <input name="FRemark" class="mini-textbox" style="width: 190px;" TabIndex="3" />
            </td>
            <td width="70px" height="40px" align="right">导航位置：</td>
            <td width="190px" height="40px" align="left">
                <input name="FLinkUrl" class="mini-buttonedit" style="width: 190px;" onbuttonclick="getClassItem('')" TabIndex="6" />
            </td>
        </tr>
        <tr style="height:30px;">
            <td></td>
            <td align="left">
                <a name="FSendFlag" class="mini-checkbox" style="width: 100px; margin-left: 10px;">是否启用</a>
            </td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
        </tr>
        <tr>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td></td>
            <td>图建议用40*40的png格式</td>
        </tr>
    </table>
    <table>
        <tr>
        </tr>
    </table>

    <table>
        <tr>
            <td width="470px" align="left">
                <div class="rightinfo">
                    <div class="tools">
                    </div>
                    <div id="div_imglist">
                    </div>
                </div>
            </td>
        </tr>
    </table>
    <table>
        <tr>
        </tr>
    </table>
    <input id="ImageFileUrl" type="hidden" />
    <input id="ImagFile0" name="ImagFile0" class="mini-hidden" />
    <input name="FItemID" class="mini-hidden" />
    <input name="FGoodsClsID" class="mini-hidden" />
    <input name="FGoodsID" class="mini-hidden" />
    <input name="FDataType" class="mini-hidden" />
</form>

<script>
    var editor1;

    var mdatatype = [{ "id": "0", "text": "轮播广告" },
    { "id": "1", "text": "分类导航" },
    { "id": "2", "text": "广告位广告" }];

    function FormShown() {
        mini.parse();
        loaded();
        $(".ke-container").css("widht", "0px");
        $(".ke-container").css("height", "0px");
    }

    //加载资料
    function SetInfoData(data) {
        if (data.action == "new") {
            //跨页面传递的数据对象，克隆后才可以安全使用
            NewInfo();
        }
        else {
            $.post("GetAdvert", { mjson: "[{'FItemID':'" + data.FItemID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                var form = new mini.Form("form1");
                var mdata = mini.decode(data);
                mini.getbyName("FItemID").setValue(mdata.data[0].FItemID);
                form.setData(mdata.data[0]);
                mini.getbyName("comdatatype").setValue(mdata.data[0].FDataType);
                mini.getbyName("FGoodsClsID").setValue(mdata.data[0].FGoodsClsID);
                if (mdata.data[0].FImgUrl != "") {
                    mini.getbyName("FImgUrl").setValue(mdata.data[0].FImgUrl);
                    $("#Image0").attr('src', mdata.data[0].FImgUrl);
                }

                if (mdata.data[0].FGoodsClsID > 0) {

                    $.post("../GoodClass/GetGoodClass", { json: "[{'FItemID':'" + mdata.data[0].FGoodsClsID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                        var ndata = mini.decode(data);
                        if (ndata.data[0].FNumber != '00')
                            mini.getbyName("FLinkUrl").setText(ndata.data[0].FName);
                    });
                }
                else {
                    if (mdata.data[0].FLinkUrl.split('/').length > 1) {
                        var GCID = mdata.data[0].FLinkUrl.split('/')[mdata.data[0].FLinkUrl.split('/').length - 1];
                        GCID = GCID.split('.')[0];
                        $.post("../GoodClass/GetGoodClass", { json: "[{'FItemID':'" + GCID + "','mSystemAppID':'" + parent.window.getSystemAppID() + "'}]" }, function (data) {
                            var ndata = mini.decode(data);
                            if (ndata.data[0].FNumber != '00')
                                mini.getbyName("FLinkUrl").setText(ndata.data[0].FName);
                        });
                    }
                }
            });
        }
    }

    //新增资料
    function NewInfo() {
        mini.getbyName("FItemID").setValue("0");
        mini.getbyName("FNumber").setValue("");
        mini.getbyName("FName").setValue("");
        mini.getbyName("comdatatype").setValue("0");
        mini.getbyName("FRemark").setValue("");
        mini.getbyName("FLinkUrl").setValue("");
        mini.getbyName("FImgUrl").setValue("");
        mini.getbyName("FGoodsClsID").setValue(0);
        mini.getbyName("FGoodsID").setValue(0);
    }

    //保存资料
    function SaveInfo() {
        mini.getbyName("save").disable();
        var form = new mini.Form("#form1");
        form.validate();
        if (form.isValid() == false) return;
        var data = form.getData(true, false);
        data.mSystemAppID = parent.window.getSystemAppID();
        var json = mini.encode(data);
        $.post("SaveAdvertise", { mjson: json }, function (data) {
            var ret = mini.decode(data);
            if (ret.status == 1) {
                mini.showTips({ content: ret.msg, state: "success", x: "center", y: "top", timeout: 3000 });
                //if (mini.getbyName("SaveNew").getValue() == "true")
                //    NewInfo();
                //else
                //    CloseWindow();
            }
            else {
                mini.alert("异常:" + ret.error);
            }
            mini.getbyName("save").enable();
        });
    }

    function getClassItem(mSearchKey) {
        var type = mini.getbyName("comdatatype").getValue()
        var tbName = '';
        mini.open({
            url: "../GetItem/index",
            title: "商品分类选择", width: 730, height: 460,
            onload: function () {
                var iframe = this.getIFrameEl();
                var data = { action: "new", sTbName: "GoodsClsInfo", sSearchKey: mSearchKey };
                iframe.contentWindow.SetData(data);
            },
            ondestroy: function (action) {
                var ID = ""; var namestr = "";
                if (action) {
                    ID = action[0].FItemID;
                    namestr = action[0].FName;
                    var data = '{mSystemAppID:"' + parent.window.getSystemAppID() + '",FItemID:"' + ID + '",BID:"0"}';
                    $.post("geturl", { json: data }, function (data) {
                        mini.getbyName("FLinkUrl").setValue(data);
                    });
                }                
                mini.getbyName("FGoodsClsID").setValue(ID);
                mini.getbyName("FLinkUrl").setText(namestr);
            }
        });
    }

    function ImageFilePath(url) {
        var result = "";
        $.ajax({
            url: "/GetItem/GetImageFilePath",
            data: { Url: url },
            type: "post",
            async: false,
            success: function (data) {
                result = data;
            },
            failure: function () {
                result = "";
            },
            error: function (jqXHR, textStatus, errorThrown) {
                return "";
            }
        });
        return result;
    }

    function loaded() {
        KindEditor.ready(function (K) {
            var editor1 = K.editor({
                uploadJson: '../asp.net/upload_json.ashx?dirs=Mall&mSystemAppID=' + parent.window.getSystemAppID() + '&thumb=true',
                fileManagerJson: '../asp.net/file_manager_json.ashx?dirs=Mall&mSystemAppID=' + parent.window.getSystemAppID(),
                allowFileManager: true
            });

            K('#Image0').click(function () {
                var url = $(this).attr('src');
                if (url.toLowerCase() != "/content/images/noimage.jpg") {
                    var cfg = confirm("你确定要删除当前图片信息？");
                    if (!cfg) {
                        return;
                    }
                    else {
                        $(this).attr('src', "/content/Images/NoImage.jpg");
                        mini.getbyName("ImagFile0").setValue("");
                        return;
                    }
                }

                editor1.loadPlugin('image', function () {
                    editor1.plugin.imageDialog({
                        imageUrl: K('#ImageFileUrl').val(),
                        clickFn: function (url, title, width, height, border, align) {
                            var path = ImageFilePath(url);
                            $("#Image0").attr('src', path);
                            $("#ImagFile0").val(path);
                            mini.getbyName("FImgUrl").setValue(url);
                            editor1.hideDialog();
                        }
                    });
                });
            });

        });
    }


    function ImageFilePath(url) {
        var result = "";
        $.ajax({
            url: "/GetItem/GetImageFilePath",
            data: { Url: url },
            type: "post",
            async: false,
            success: function (data) {
                result = data;
            },
            failure: function () {
                result = "";
            },
            error: function (jqXHR, textStatus, errorThrown) {
                return "";
            }
        });
        return result;
    }

</script>
